package com.hg.chapter4.upload;

import org.apache.commons.io.FileUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@RestController
public class MyUpload {

    @PostMapping("/upload")
    public @ResponseBody String upload(MultipartFile file) throws IOException {
        FileUtils.writeByteArrayToFile(new File("/Users/gang/project"+file.getOriginalFilename()),file.getBytes());
        return "ok!!!";
    }
}
